<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <p id="content">1</p>
  <button id="btn">点击+1</button>

  <script>

    let btn = document.querySelector('#btn')
    let p = document.querySelector('#content')
    let obj = {
      value: 1
    }
    let value = 1  //存放obj.value

    Object.defineProperty(obj, 'value', {
      get() {
        return value
      },
      set(newVal) {
        value = newVal
        p.innerHTML=newVal  //p标签放的值为最新值
      }
    })

    btn.addEventListener('click', () => {
      // p.innerHTML = Number(p.innerHTML) + 1
      obj.value+=1   //如果要响应，只需要改变这里的值
      console.log(obj.value);
    })
  </script>
</body>

</html>